import { createStore } from 'vuex'

export default createStore({
  state: {
    teacher: null,
    classList: [],
    courseList: []
  },
  mutations: {
    setTeacher(state, teacher) {
      state.teacher = teacher
    },
    setClassList(state, list) {
      state.classList = list
    },
    setCourseList(state, list) {
      state.courseList = list
    }
  },
  actions: {
    async fetchTeacher({ commit }, id) {
      const res = await teacherApi.getTeacher(id)
      commit('setTeacher', res.data)
    },
    async fetchClassList({ commit }, teacherId) {
      const res = await teacherApi.findClassByTeacher(teacherId)
      commit('setClassList', res.data)
    },
    async fetchCourseList({ commit }, teacherId) {
      const res = await courseApi.getTeacherCourseList(teacherId)
      commit('setCourseList', res.data)
    }
  }
})